package com.may.nio;

import java.nio.ByteBuffer;
import java.util.stream.IntStream;

/**
 * @program: com.may.netty
 * @description: 只读 buffer
 * @author: Bobby.Ma
 * @create: 2020-08-02 16:43
 **/
public class ReadOnlyBuffer {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(64);
        IntStream.range(0, 64).forEach(i -> buffer.put((byte) i));
        buffer.flip();
        ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
        while (readOnlyBuffer.hasRemaining()) {
            System.out.println(readOnlyBuffer.get());
        }
//        readOnlyBuffer.put((byte)100);//ReadOnlyBufferException
    }
}
